//
//  BSCommtentTableViewCell.m
//  BS
//
//  Created by 王浩宇 on 15/8/17.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "BSCommtentTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "UIButton+WebCache.h"
#import "UILabel+LJLabel.h"

@implementation BSCommtentTableViewCell

- (void)awakeFromNib {
    // Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)setDataModel:(BSComtentDataModel *)dataModel
{
    _dataModel = dataModel;
    _useHeadImage.layer.cornerRadius = 15;
    if ([dataModel.user[@"sex"] isEqualToString:@"m"]) {
        _sexImage.image = [UIImage imageNamed:@"Profile_manIcon"];
    }else{
        _sexImage.image = [UIImage imageNamed:@"nv"];
    }
    if ([dataModel.user[@"profile_image"] isEqualToString:@""]) {
        [_useHeadImage setImage:[UIImage imageNamed:@"profile_image"] forState:UIControlStateNormal];
    }else{
    [_useHeadImage sd_setBackgroundImageWithURL:[NSURL URLWithString:dataModel.user[@"profile_image"]] forState:UIControlStateNormal];
    }
    _useNameLabel.text = dataModel.user[@"username"];
    _content.text = dataModel.content;
    _praiseCountLabel.text = dataModel.like_count;
    [_content adaptationHeight];

}


- (void)setHotModel:(BSComtentHotModel *)hotModel
{
    _hotModel = hotModel;
    if ([hotModel.user[@"sex"] isEqualToString:@"m"]) {
        _sexImage.image = [UIImage imageNamed:@"Profile_manIcon"];
    }else{
        _sexImage.image = [UIImage imageNamed:@"nv"];
    }
        if ([hotModel.user[@"profile_image"] isEqualToString:@""]) {
        [_useHeadImage setImage:[UIImage imageNamed:@"setup-head-default"] forState:UIControlStateNormal];
    }else{
         [_useHeadImage sd_setBackgroundImageWithURL:[NSURL URLWithString:hotModel.user[@"profile_image"]] forState:UIControlStateNormal];
    }
    _useNameLabel.text = hotModel.user[@"username"];
    _content.text = hotModel.content;
    _praiseCountLabel.text = hotModel.like_count;
    [_content adaptationHeight];
}


- (IBAction)touser:(UIButton *)sender {
    
//    NSLog(@"跳到用户界面");
}

- (IBAction)praiseButton:(id)sender {
    
    if (_praiseButton.selected == YES) {
        _praiseButton.selected = NO;
        self.dataModel.like_count = @"0";
        _praiseCountLabel.text = [NSString stringWithFormat:@"%d",[_praiseCountLabel.text intValue] - 1];
    }else{
        _praiseButton.selected = YES;
        self.dataModel.like_count = @"1";
        _praiseCountLabel.text = [NSString stringWithFormat:@"%d",[_praiseCountLabel.text intValue] + 1];
    }
}


+ (CGFloat)cellHeight:(BSComtentDataModel *)datamodel
{
    CGFloat hight = [UILabel heightOfLabelByStr:datamodel.content fontSize:14 width:193];
    return hight + 40;
}


+ (CGFloat)cellHeigh:(BSComtentHotModel *)datamodel
{
    CGFloat hight = [UILabel heightOfLabelByStr:datamodel.content fontSize:14 width:193];
    return hight + 40;
}




@end
